import request from '@/utils/request'
import { MenuTreeDTO } from '@/model/auth/MenuTreeDTO'
import { SetMenuDTO } from '@/model/auth/SetMenuDTO'

/**
 * 根据角色获取菜单
 * @param userId
 */
export function listByRoleId(roleId: number): Promise<Array<MenuTreeDTO>> {
  return request.get('/api/auth/module/listByRole', {
    roleId,
  })
}

/**
 * 设置角色菜单
 * @param data
 */
export function updateModuleByRole(data: SetMenuDTO) {
  return request.put('/api/auth/module/updateModuleByRole', data)
}

/**
 * 获取菜单
 * @param params
 */
export function listMenu(params: {}): Promise<Array<MenuTreeDTO>> {
  return request.get('/api/auth/module/list', params)
}

/**
 * 新增菜单
 * @param data
 */
export function addMenu(data: MenuTreeDTO) {
  return request.post('/api/auth/module', data)
}

/**
 * 修改菜单
 * @param data
 */
export function updateMenu(data:MenuTreeDTO) {
  return request.put(`/api/auth/module/${data.id}`, data)
}

/**
 * 删除菜单
 * @param id
 */
export function deleteMenu(id:number) {
  return request.delete(`/api/auth/module/${id}`)
}
